#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
const int N=2*1e5+5;
ll n;
ll dp[N];
ll nums[N];
int main() 
{
    cin>>n;
    for(int i=1;i<=n;i++)cin>>nums[i];
    ll ret=-0x3f3f3f3f3f3f3f3f;
    for(int i=1;i<=n;i++)
    {
        dp[i]=nums[i];
        dp[i]=max(dp[i-1]+nums[i],dp[i]);
        ret=max(ret,dp[i]);
    }
    cout<<ret<<endl;
}
// 64 位输出请用 printf("%lld")